# coding=utf-8
import os
import re
import sys

reload(sys)
sys.setdefaultencoding('utf-8')
PWD = os.path.dirname(os.path.abspath(__file__))


def append(fo, lines):
    for line in lines:
        fo.write("%s\n" % line)


def make_dir(path):
    if not os.path.isdir(path):
        os.mkdir(path)


def read(path):
    fo = open(path, "r")
    rtn = fo.read()
    fo.close()
    return rtn


def write(path, content):
    fo = open(path, "wb")
    if isinstance(content, list):
        for line in content:
            fo.write(line)
            fo.write("\n")
    else:
        fo.write(content)
    fo.close()


def ls(path):
    return walk(path)


def walk(path):
    rtn = []
    nodes = os.walk(path)
    for path, d, files in nodes:
        for fileName in files:
            rtn.append(os.path.join(path, fileName))
    return rtn


def root_path():
    return os.path.dirname(os.path.dirname(PWD))

